﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;
using FarseerPhysics.Common;
using FarseerPhysics.Collision.Shapes;
using FarseerPhysics.Controllers;
using GameStateManagement;

namespace BHG.System
{
    class BlackHoleGunObject : BallObject
    {
        const float BLACKHOLE_RADIUS = 2.0f;
        const float BLACKHOLE_STRENGHT = 550.0f;    // BH strenght
        const float BLACKHOLE_INTERVAL = 1.0f;      // interval how long BH stays active in seconds
        const float ROTATION_X = 0.000001f;

        protected GravityController BlackHole;
        protected double killTime;

        public BlackHoleGunObject( Vector2 pos, Model model, GameTime createdTime )
            : base(pos, BLACKHOLE_RADIUS, 0.0f, false, model) {
            this.killTime = BLACKHOLE_INTERVAL;
            BlackHole = PhysicsEngine.Instance.AddGravityCenter(this, FarseerPhysics.Controllers.GravityType.DistanceSquared, BLACKHOLE_STRENGHT);
        }

        public void KillBlackHole()
        {
            this.killTime -= BLACKHOLE_INTERVAL;
        }

        public override void Update( GameTime gameTime ) {
            base.Update(gameTime);
            this.Rotation += ROTATION_X*gameTime.ElapsedGameTime.Ticks;
            this.killTime -= gameTime.ElapsedGameTime.TotalSeconds;
            if ( killTime <= 0 ) 
            {
                //this.Position = new Vector2(-1000, -1000);
                this.state = State.REMOVED;
            }
        }

        public override void doRemove() {
            base.doRemove();
            PhysicsEngine.Instance.gameWorld.RemoveController(BlackHole);
            //PhysicsEngine.Instance.removeObjectFromPhysics(this);
        }
    }
}
